/**
 * 插件基础类，项目文件的入口
 * 1.n2.using(n2.main,['n2.xxx'])  注册所有的插件
 * 2.获取插件单例
 * n2.getInstance('n2.XXX', self).then(function (obj) {
        //TODO 功能逻辑 
    });
    例子：
    n2.getInstance('n2.satellite', self).then(function (obj) {
        obj.init();
    });
 */
namespace('n2.main');
n2.main = function() {
	this._version = 1.0; //版本号
	this._initPosition = [108.400975, 36.903325, 20000000]; //初始镜头位置
	this._viewer = null;
	this._flags = {
		looking: false,
		moveForward: false,
		moveBackward: false,
		moveUp: false,
		moveDown: false,
		moveLeft: false,
		moveRight: false,
		restart: false
	};
};

n2.using(n2.main, ['n2.rightBtn', 'n2.billboard', 'n2.tms', 'n2.yingji', 'n2.layerControl', 'n2.simulate']);

n2.definePrototype(n2.main.prototype, {
	version: {
		get: function() {
			return this._version;
		}
	},
	initPosition: {
		get: function() {
			return this._initPosition;
		}
	},
	viewer: {
		get: function() {
			return this._viewer;
		},
		set: function(value) {
			this._viewer = value;
		}
	}
});

n2.main.prototype.dizheng = function() {
	var self = this;
	self.init(); //加载球
	self.simulate(); //框架测试
	setTimeout(function() {
		self.rightBtn(); //加载功能图表以及功能事件，双击放大并飞行到双击位置，双击飞行到某一点，南海诸岛根据视角的高度消失，出现		
		self.basicServer(); //基础geoserver的wms服务
		self.billboard(); //地震页面的billbord 的生成及点击事件
		//		self.tms();           //加载tms瓦片
		self.layerCl(); //图层控制
	}, 5000)
}

n2.main.prototype.xiangying = function() {
	var self = this;
	self.init(); //加载球
	self.rightBtn(); //加载功能图表以及功能事件，双击放大并飞行到双击位置，双击飞行到某一点，南海诸岛根据视角的高度消失，出现
	self.yingji(); //应急页面的billbord 的生成及点击事件
	self.basicServer(); //基础geoserver的wms服务
	self.layerCl(); //图层控制
}

n2.main.prototype.init = function() {
	//初始化球面
	var self = this;
	//	console.log(self)
	n2.viewer = new Cesium.Viewer('cesiumContainer', {
		homeButton: false,
		geocoder: false,
		baseLayerPicker: false,
		navigationHelpButton: false,
		fullscreenButton: false, //全屏按钮,默认显示true
		selectionIndicator: false, //选中元素显示,默认true
		timeline: false,
		infoBox: false,
		animation: false,
		shadows: false,
		scene3DOnly: true, //true   每个实例只能以3d渲染，节省gpu内存
		terrainShadows: true,

	});
	//加入背景图片出现bug未能显示，那么地图颜色更改为黑色（默认为蓝色地球）
//	  var globe = n2.viewer.scene.globe;
//		globe.baseColor = new Cesium.Color(0.0, 0.0, 0.0, 0.0);
//		new Cesium.ImageryLayerCollection();
	//视角定位到中国
	
	self.viewer = n2.viewer;
//	console.log(self.viewer);
	self.viewer.camera.flyTo({
		destination: new Cesium.Cartesian3.fromDegrees(self._initPosition[0], self._initPosition[1],10000000)
	});
    //删除Cesium图标*/
	document.getElementsByClassName('cesium-viewer-bottom')[0].style.display = 'none';
}

/**
 * 基础geoserver的wms(web map server)服务，测试接口，已废弃
 */

n2.main.prototype.basicServer = function() {
	var self = this;
	var viewer = self.viewer;

	//  var wms = new Cesium.WebMapServiceImageryProvider({
	//       url: "http://" + n2.geoServer + "/geoserver/gwc/service/wms?LAYERS=china%3AworldchinaVector2015&FORMAT=image%2Fpng&SERVICE=WMS&VERSION=1.1.0&REQUEST=GetMap&STYLES=&SRS=EPSG%3A4326&WIDTH=256&HEIGHT=256",
	//       layers: "china:chinaVector2015",
	////       proxy: new Cesium.DefaultProxy("/proxy/"),
	//       enablePickFeatures: false     //选项框
	//      
	//   })
	//  viewer.scene.imageryLayers.addImageryProvider(wms)

}

/*
加载右侧点击按钮时间   加载功能图表以及功能事件（生成图标后期除去）
 */

n2.main.prototype.rightBtn = function() {
	var self = this;
	n2.getInstance('n2.rightBtn', self).then(function(obj) {
		obj.init();
	});
}

/**
 * billbord 的生成与点击事件
 */

n2.main.prototype.billboard = function() {
	var self = this;
	n2.getInstance('n2.billboard', self).then(function(obj) {
		obj.init();
	});
}

//TMS服务加载
n2.main.prototype.tms = function() {
	var self = this;
	n2.getInstance('n2.tms', self).then(function(obj) {
		obj.init();
	});
}

/**
 * billbord 的生成与点击事件
 */
n2.main.prototype.yingji = function() {
	var self = this;
	n2.getInstance('n2.yingji', self).then(function(obj) {
		obj.init();
	});
}

//图层控制
n2.main.prototype.layerCl = function() {
	var self = this;
	n2.getInstance('n2.layerControl', self).then(function(obj) {
		obj.init();
	});
}

//测试数据
n2.main.prototype.simulate = function() {
	var self = this;
	n2.getInstance('n2.simulate', self).then(function(obj) {
		obj.init();
	});
}
// rectangle: new Cesium.Rectangle(
//       Cesium.Math.toRadians(108.0),
//       Cesium.Math.toRadians(29.0),
//       Cesium.Math.toRadians(116.0),
//       Cesium.Math.toRadians(33.0))